package com.css.dzj.dzjdzqs.modules.apaction.apforce.service.impl;

import com.alibaba.fastjson.JSON;
import com.css.dzj.dzjdzqs.common.util.HttpClientUtil;
import com.css.dzj.dzjdzqs.modules.apaction.apforce.Vo.ApForceVo;
import com.css.dzj.dzjdzqs.modules.apaction.apforce.entity.ApForceEntity;
import com.css.dzj.dzjdzqs.modules.apaction.apforce.mapper.ApForceMapper;
import com.css.dzj.dzjdzqs.modules.apaction.apforce.service.ApForceService;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author WT
 * @Date 2020/6/28
 */
@Service
public class ApForceServiceImpl implements ApForceService {

    @Autowired
    JPAQueryFactory jpaQueryFactory;
    @Autowired
    private ApForceMapper apForceMapper;
    @Value("${AP_URL}")
    private String apUrl;

    @Override
    @Transactional
    public void add(List<ApForceVo> apForceVoList) {

        try {
            for(ApForceVo apForceVo :apForceVoList){
                ApForceEntity apForce = new ApForceEntity();
                apForce.setForceId(apForceVo.getForceId());
                apForce.setRecordUniqueIdentity(apForceVo.getRecordUniqueIdentity());
                apForce.setSuperviseItemCode(apForceVo.getSuperviseId());
                apForce.setForceActionName(apForceVo.getForceActionName());
                apForce.setForceActionCode(apForceVo.getForceActionCode());
                apForce.setImplementInstitution(apForceVo.getImplementInstitution());
                apForce.setImplementInstitutionCode(apForceVo.getImplementInstitutionCode());
                apForce.setSuperviseObject(apForceVo.getSuperviseObject());
                apForce.setCheckActionCode(apForceVo.getCheckActionCode());
                apForce.setAdministrativeCp(apForceVo.getAdministrativeCp());
                apForce.setAdministrativeCpNa(apForceVo.getAdministrativeCpNa());
                apForce.setAdministrativeCpCeType(apForceVo.getAdministrativeCpCeType());
                apForce.setAdministrativeCpUiCode(apForceVo.getAdministrativeCpUiCode());
                apForce.setAddressRegistered(apForceVo.getAddressRegistered());
                apForce.setAddressOperating(apForceVo.getAddressOperating());
                apForce.setAreaNumber(apForceVo.getAreaNumber());
                apForce.setIllegalFact(apForceVo.getIllEgalFact());
                apForce.setMandatoryBasis(apForceVo.getForceAccord());
                apForce.setMandatoryDecisionNumber(apForceVo.getMandatoryDecisionNumber());
                apForce.setForceType(apForceVo.getForceType());
                apForce.setCoerciveMeasureType(apForceVo.getCoerciveMeasureType());
                apForce.setForceExecutionType(apForceVo.getForceExecutionType());
                apForce.setMandatoryDecisionPatify(apForceVo.getMandatoryDecisionPatify());
                apForce.setMandatoryDecisionSevDate(apForceVo.getMandatoryDecisionSevDate());
                apForce.setForceExtendDate(apForceVo.getForceExtendDate());
                apForce.setEndDate(apForceVo.getEndDate());
                apForce.setSubmittedDate(apForceVo.getSubmittedDate());
                apForce.setSubmittedPersonnel(apForceVo.getSubmittedPersonnel());
                apForceMapper.save(apForce);
            }
        }catch (Exception e){
            e.printStackTrace();
        }

    }

    @Override
    @Transactional
    public void pushtForce() {

        try{
            String msg = HttpClientUtil.doGet(apUrl+"/force/getApList");
            List<ApForceVo> apForceVoList = JSON.parseArray(msg, ApForceVo.class);
            if(null!=apForceVoList && apForceVoList.size()>0){
                add(apForceVoList);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
